package com.joker.springboottestdemo.job;


import com.joker.demo.core.annotation.JobHandle;
import com.joker.demo.core.domain.dto.JobExecutorParamsDTO;
import com.joker.demo.core.domain.dto.JobExecutorResultDTO;
import com.joker.demo.core.executor.JobExecutorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * 这种的支持分片参数
 *
 * @author : feixiang.li
 * @since : 2025-07-27 16:57
 */
//@JobHandle(value = "demoJobSharingHandler", cron = "0/5 * * * * ?")
@Service
@Slf4j
public class SimpleJobSharingService implements JobExecutorService {


    @Override
    public JobExecutorResultDTO execute(JobExecutorParamsDTO jobExecutorParamsDTO) {
        log.info("执行任务开始:{}", jobExecutorParamsDTO);

        for (int i = 0; i < 5; i++) {
            log.info("任务执行中：{}", i);
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (Exception e) {
                log.error("任务执行异常", e);
            }
        }

        return new JobExecutorResultDTO("success");
    }
}
